package com.example.healthsystem.service.impl;

import com.example.healthsystem.entity.healthreg;
import com.example.healthsystem.exception.PersistenceException;
import com.example.healthsystem.mapper.HealthregMapper;
import com.example.healthsystem.service.HealthregService;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class HealthregServiceImpl implements HealthregService {
    @Autowired
    HealthregMapper healthregMapper;

    @Override
    public void insertHealth(healthreg healthreg){
        if(healthregMapper.insertHealth(healthreg)==0){
            throw new PersistenceException("无法插入健康表中的新数据");
        }
    }

    @Override
    public void deleteReginfo(String name){
        if(healthregMapper.deleteReginfo(name)==0){
            throw new PersistenceException("无法删除健康表中的信息");
        }
    }

    @Override
    public void changeReginfo(String name,healthreg healthreg){
        if(healthregMapper.changeReginfo(name,healthreg)==0){
            throw new PersistenceException("无法更新健康表中的信息");
        }
    }

    @Override
    public List<healthreg> searchHealthPer(String name,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return healthregMapper.searchHealthPer(name);
    }

    @Override
    public List<healthreg> searchHealth(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        return healthregMapper.searchHealth();
    }

    @Override
    public healthreg searchHealthDate(String name, Timestamp time){
//        PageHelper.startPage(pageNum, pageSize);
        return healthregMapper.searchHealthDate(name, time);
    }
}
